# Enable italic font in iterm2
# Refer to http://apple.stackexchange.com/questions/249307/tic-doesnt-read-from-stdin-and-segfaults-when-adding-terminfo-to-support-italic/249385
# set -g default-terminal "tmux-256color"

# invoke reattach-to-user-namespace every time a new window/pane opens
# if-shell doesn't always work
if-shell '[ $(uname -s) = Darwin ]' \
    'set -g default-terminal "xterm-256color"; set -g default-command bash'
    # Sierra remove reattach-to-user-namespace
    # 'set -g default-terminal "tmux-256color"; set -g default-command "reattach-to-user-namespace -l bash"'

# 设置终端类型为256色
if-shell '[ $(uname -s) = Linux ]' \
    'set -g default-terminal "screen-256color"'

set -g history-limit 102400

# Add truecolor support
set-option -ga terminal-overrides ",*256col*:Tc"

# set -as terminal-overrides ',xterm*:sitm=\E[3m'
# 开启剪切板
set -g set-clipboard on

# 关闭窗口后重新编号
set -g renumber-windows on

# Index starts from 1
set-option -g base-index 1
setw -g pane-base-index 1   # make pane numbering consistent with windows

setw -g automatic-rename on # rename window to reflect current program
set -g renumber-windows on  # renumber windows when a window is closed

set -g set-titles on                        # set terminal title
set -g set-titles-string '#h ❐ #S ● #I #W'

# 事件窗口信息，如有内容变动，进行提示
setw -g monitor-activity on
set -g visual-activity on
# set -g status-utf8 on          #  在状态栏开启UTF-8
set -g history-limit 102400    #  scrollback buffer n lines
set -g mode-keys vi    #  user vi mode

set -g repeat-time 0

# 支持鼠标选择窗口，调节窗口大小
#setw -g mode-mouse on
#set -g mouse-select-pane on
#set -g mouse-resize-pane on
#set -g mouse-select-window on

# 设置重新连接不同窗口大小的tmux
setw -g aggressive-resize on

# select-pane (@george-b)
bind-key 0 run "tmux split-window -p 40 'bash -ci ftpane'"

# set -g default-shell /bin/zsh

# 重新绑定纵向和横向切分window快捷键。|，-，更直观地表明了切割方向
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# 在不同面板间切换，改为vim风格
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# 快速选择面板
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
# 调整面板大小
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# 设置前缀键，默认为Ctrl+b
# set -g prefix C-b
# 释放之前的Ctrl-b前缀快捷键
# unbind C-b

#jtmux有一个延时以方便用户按键组合，默认有点长。这里设置为1秒钟
set -s escape-time 1

# 设置动态加载tmux配置文件的快捷键
bind r source-file ~/.tmux.conf \; display "Configuration Reloaded"

# 设置窗口标签的前景及背景色
# setw -g window-status-fg colour72
# setw -g window-status-bg colour238
# junegunn
set-window-option -g window-status-format '#[bg=colour238]#[fg=colour107] #I #[bg=colour239]#[fg=colour110] #[bg=colour240]#W#[bg=colour239]#[fg=colour195]#F#[bg=colour238] '
set-window-option -g window-status-current-format '#[bg=colour236]#[fg=colour215,bold] #I:#[bg=colour235]#[fg=colour167] #[bg=colour234]#W#[bg=colour235]#[fg=colour195]#F#[bg=colour236] '
setw -g window-status-style dim

# 设置当前窗口标签的前景及背景色,所谓当前窗口标签会显示在状态栏中间
# setw -g window-status-current-style fg=colour22
# setw -g window-status-current-style bg=colour73
# setw -g window-status-current-style bright

# 设置窗口分割的边框颜色
# set -g pane-border-style fg=yellow
set -g pane-border-style fg=colour237
# set -g pane-border-style bg=black

# 设置当前窗口分割的边框颜色
# set -g pane-active-border-style fg=green
set -g pane-active-border-style fg=colour240
# set -g pane-active-border-style bg=yellow

# 设置提示信息的前景及背景色, e.g, Reload
set -g message-style fg=colour168,bg=colour237,bright

#set -g set-titles-string '#T'

###################  状态栏设置  ###############################
# 以下色彩为mac环境下，Linux下可能需重新设置颜色
# 设置状态栏前景色，背景色
#set -g status-fg white
#set -g status-bg black

# 设置状态栏前景及背景色
set -g status-bg colour237
set -g status-fg colour68

# 设置状态栏左部宽度  默认为10
set -g status-left-length 45
# 设置状态栏左部显示内容。
# https://gitlab.com/gnachman/iterm2/issues/6666
# set -g status-left "#[fg=colour252,bold,bg=colour243] 🌺  S: #S #[fg=colour250,bg=colour239] 🏵  W: #I #[fg=yellow,bg=colour237] ☘ #[fg=colour250,bg=colour237] P: #P#[default]"
# set-option -g status-left '#[bg=colour72] #[bg=colour234] #[bg=colour235] #[bg=colour236]#[fg=colour185,bg=colour238] 🌺  S:#S #[fg=colour251,bg=colour239] 💻  #h '
# set-option -g status-left '#[bg=colour72] #[bg=colour236] #[bg=colour237]#[fg=colour185,bg=colour238] 🌺  S:#S #[fg=colour251,bg=colour239] 💻  #h '
set-option -g status-left '#[bg=colour72] #[bg=colour236] #[bg=colour237]#[fg=colour185,bg=colour238]  S:#S #[fg=colour251,bg=colour239] h:#h '
# 设置状态栏右部宽度
set -g status-right-length 48
# 设置状态栏右部内容，这里设置为时间信息
# macOS
# set -g status-right "#[fg=colour251,bg=colour239] 🗓  %b-%d #[fg=colour251,bg=colour238] ⏱  %R #[fg=colour251,bg=colour237] 🐳  #(ifconfig | grep 'inet.*netmask.*broadcast' | awk '{print $2}') #[bg=colour236] #[bg=colour235] #[bg=colour72] "
set -g status-right "#[fg=colour251,bg=colour239]%b-%d #[fg=colour251,bg=colour238] %R #[fg=colour251,bg=colour237] #(ifconfig | grep 'inet.*netmask.*broadcast' | awk '{print $2}') #[bg=colour236] #[bg=colour235] #[bg=colour72] "

set -g status-right "#[fg=colour251,bg=colour239]%b-%d #[fg=colour251,bg=colour238] %R #[fg=colour251,bg=colour237] #(ifconfig | grep 'inet.*netmask.*broadcast' | awk '{print $2}') #[bg=colour236] #[bg=colour235] #[bg=colour72] "

set-option -g status-left "#[fg=colour248, bg=colour241] S:#S #[fg=colour241, bg=colour237, nobold, noitalics, nounderscore]"
set-option -g status-right "#[fg=colour239, bg=colour237, nobold, nounderscore, noitalics]#[fg=colour246,bg=colour239] %Y-%m-%d  %H:%M #[fg=colour248, bg=colour239, nobold, noitalics, nounderscore]#[fg=colour237, bg=colour248] #(ifconfig | grep 'inet.*netmask.*broadcast' | awk '{print $2}') "
# Ubuntu
# set -g status-right "#[fg=colour251,bg=colour239] 🗓  %b-%d #[fg=colour251,bg=colour238] ⏱  %R #[fg=colour251,bg=colour237] 🐳  #(ifconfig | grep 'inet addr:192' | cut -d: -f2 | awk '{print $1}') #[bg=colour236] #[bg=colour72] "
# 窗口信息居中显示
set -g status-justify centre
# 设置状态栏更新时间 每60秒更新一次，默认是15秒更新
set -g status-interval 60

# https://github.com/neovim/neovim/wiki/FAQ#cursor-shape-doesnt-change-in-tmux
set -g -a terminal-overrides ',*:Ss=\E[%p1%d q:Se=\E[2 q'

# Move status bar to the top
# set-option -g status-position top
set-option -g status-position bottom
